package com.shenbianyun.bosskgpay.service.invoice;

import com.shenbianyun.bosskgpay.constant.MerInfoConstant;
import com.shenbianyun.bosskgpay.entity.Merchant;
import com.shenbianyun.bosskgpay.entity.RequestMessage;
import com.shenbianyun.bosskgpay.entity.invoice.ApplyInvoiceReqModel;
import com.shenbianyun.bosskgpay.utils.*;

/**
 * @Author yvan
 * @Date 2021/11/23 11:14:55
 * @Description //商户申请开票6013
 * 可固定业务参数
 **/
public class TestApplayInvoiceService {


    public static ApplyInvoiceReqModel applyInvoice = null;
    static Merchant mer = null;

    public static void main(String[] args) throws Exception {
        new  TestApplayInvoiceService().runTestApplayInvoiceService();
    }


    public void runTestApplayInvoiceService() throws Exception {
        mer = new Merchant();
        /*
         * 商户id
         * */
        mer.setMerid(MerInfoConstant.MER_ID);
        /*
         * 商户私钥
         * */
        mer.setPriKey(MerInfoConstant.MER_PRIVATE_KEY);
        /*
         * 商户公钥
         * */
        mer.setPubKey(MerInfoConstant.MER_PUBLIC_KEY);
        /*
         * 商户签名
         * */
        mer.setInterKey(MerInfoConstant.INTER_KEY);

        //公共参数
        RequestMessage rm = new RequestMessage();
        //接口地址
        rm.setFunCode("6013");
        rm.setMerId(mer.getMerid());
        rm.setVersion(MerInfoConstant.API_VERSION);
        rm.setReqId(rm.getFunCode() + System.currentTimeMillis());

        //业务参数
        applyInvoice = new ApplyInvoiceReqModel();
        //服务商id
        applyInvoice.setProviderId(30481L);//31720L
        //发票类目id
        applyInvoice.setInvoiceTypeId(10500L);//10358L
        //金额（分）
        applyInvoice.setAmt(10L);//
//      以下为选填(不填则默认从取商户开户时提供的开票信息）
        applyInvoice.setInvoiceMemo("压测-申请开票备注信息");
        applyInvoice.setContact("联系人来自接口");
        applyInvoice.setMobile("18832016331");
        applyInvoice.setPostAddress("地址来自接口");


        //reqData转json
        String reqData = JsonUtils.toJson(applyInvoice);
        System.out.println("reqDatajson= " + reqData);

        //reqData加密
        byte[] bs = DESUtils.encrypt(reqData.getBytes(MerInfoConstant.CHARSET_UTF_8), mer.getInterKey());
        String reqDataEncrypt = Base64Utils.encodeToString(bs);
        rm.setReqData(reqDataEncrypt);
        rm.setSign(RSAUtils.sign(reqDataEncrypt, mer.getPriKey()));

        String reqStr = JsonUtils.toJson(rm);
        System.out.println("请求数据：" + reqStr);

        //发送请求
        String resData = HttpClientHelper.sendPost(MerInfoConstant.OMS_TEST_URL, "application/json", reqStr, "POST", MerInfoConstant.CHARSET_UTF_8);
        System.out.println("返回数据："+resData);

    }
}
